<?php
header('Content-Type:text/html;charset=utf-8');
require_once('include/config.php');
require_once('include/wp-db.php');
require_once('include/utils.php');
require_once('include/page_class.php');
$time=time();

if(isset($_REQUEST['page']))
{
	$page =intval($_REQUEST["page"]);
}else{
	
$page =0;
}


$perPage =8;
$startnum = ((($page > 1)?$page:1)-1) * $perPage;
$endnum = $perPage;
$totalnum = $wpdb->get_var("SELECT count(*) from miao_cp  where nums>0 and  str_begintime>='$time' and flag=1");
$pages = ceil($totalnum/$perPage);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>汉庭海友客栈</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/jquery-1.6.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
	
	countDown()
	$('.gtl').click(function(){
		$("#login").before("<div id='exposeMask' style='*height:"+$("body").height()+"px'></div>");
		$("#login").show();
    });
	$('.close').click(function(){
		$("#exposeMask").remove();
		$("#login").hide();
    });

});


var NowTime = new Date();

				  //计算出服务器和客户端的时间差。
 var dTime = <?php echo   $time*1000 ;?>-NowTime.getTime();
function countDown(){
	var all = $("input[id^='item_ids_']");
	for (i=0; i< all.length; i++)
	{
		var id = all[i].value;
		
	   var NowTime = new Date();
	   var sutime= NowTime.getTime();
	   var lasttime = $("#lasttime_" + id).val();
	   var starttime= $("#stime_" + id).val();
	   var showtime=$("#showtime_" + id).val();
		
	    lasttime=lasttime*1000;
		
	//	alert(starttime);
		
		var s_l_time=0;
		s_l_time=<?php echo  $time ;?>-starttime;
		
	    var nowtime = Date.parse(new Date());
		var time = lasttime- nowtime-dTime;
		var str='';
		
		if(s_l_time<=0)
		{
			str=showtime;
			$("#item_time_display_" + id).html(str);	
			
		}
		else if (Math.floor(time) <= 0)
		{
			$("#item_time_display_" + id).html('秒杀已结束');
		}
		else
		{
			var tday=Math.floor(time/(86400*1000));
			var thour=Math.floor(time/(3600*1000))%24;
			var tminute=Math.floor(time/(60*1000))%60;
			var tsecond=Math.floor(time/1000)%60;
			str="距离结束：<em>"+tday+"</em>天<em>"+thour+"</em>时<em>"+tminute+"</em>分<em>"+tsecond+"</em>秒";			
			$("#item_time_display_" + id).empty();
			$("#item_time_display_" + id).html(str);
		}
	}
	setTimeout('countDown()',1000);
}

</script>
</head>
<body>
<div id="header">
	<div class="logo"><a href="#"></a></div>
	<div class="menu">
		<ul>
			<li><a href="./"><img src="images/menu_1.png" alt="首页" /></a></li>
			<li><a href="list.php"><img src="images/menu_2.png" alt="今日秒杀" /></a></li>
			<li><a href="next.php"><img src="images/menu_3_.png" alt="下期预告" /></a></li>
			<li><a href="photo.php"><img src="images/menu_4.png" alt="客栈相册" /></a></li>
			<li><a href="qa.php"><img src="images/menu_5.png" alt="常见问题" /></a></li>
		</ul>
	</div>
	<div class="banner">
		<div class="nav">
			<ul>
				<li><a class="gtl"><img src="images/nav_login.png" /></a></li>
				<li><a href="./h/index.html"><img src="images/nav_hello.png" /></a></li>
				<li><a href="explain.php"><img src="images/nav_explain.png" /></a></li>
				<li><a href="http://www.htinns.com/hanting/KZDefault.aspx"  target="_blank"><img src="images/nav_website.png" /></a></li>
			</ul>
		</div>
			<?php include('share.php');?>
	</div>
</div>
<div id="main" class="fix">
	<div style="padding:26px 0 0 16px;height:49px"><img src="images/tit_jj.png" /></div>
	<div class="slist">
		<ul class="fix">
			<?php
            $sql_cp="select * from miao_cp  where nums>0 and  str_begintime>='$time' and flag=1 order by id asc  limit $startnum,$endnum ";
			
			$rs_cp=$wpdb->get_results($sql_cp);
			if($rs_cp!=NULL)
			{
				foreach($rs_cp as $cp_v)
				{
					$id=$cp_v->id;
					$subtitle=$cp_v->subtitle;
					$miaoprice=$cp_v->miaoprice;
					$begintime=$cp_v->begintime;
					$endtime=$cp_v->endtime;
					$imgpath=$cp_v->imgpath;
					$nowtime=time();
					
					$str_begintime=$cp_v->str_begintime;
					$str_endtime=$cp_v->str_endtime;
					
					
					$rediturl='';
					$btnstr='';
					$datestr='';
					if(($nowtime)<=($str_begintime))
					{
						$rediturl='r_detail.php?d='.$id;	
						$btnstr='images/btn_jj.png';
						$datestr=0;	
						
						
					}
					elseif(($nowtime)>=($str_begintime) && ($nowtime)<=($str_endtime))
					{
						$rediturl='r_detail.php?d='.$id;
						$btnstr='images/btn_ms.png';	
						$datestr=1;			
					}
					else
					{
						$rediturl='r_detail.php?d='.$id;	
						$btnstr='images/btn_jj.png';
						$datestr=0;	
					}
					
					$month=date('m',$str_begintime);
					$day=date('d',$str_begintime);
					$hour=date('H',$str_begintime);
					
					
					?>
			 <li>
					<a href="<?php echo $rediturl;?>" class="pic"><img src="upload/hotel/<?php echo $imgpath?>" /><span><?php echo $subtitle?></span></a>
					<span class="time">秒杀价<b>￥</b><strong><?php echo $miaoprice;?></strong>&nbsp;<label id="item_time_display_<?php echo $id?>"></label></span>
                    
                    <input id="lasttime_<?php echo $id?>" type="hidden" value="<?php echo $str_endtime;?>"/>
					<input id="item_ids_<?php echo $id?>" type="hidden" value="<?php echo $id?>"/>
               		<input id="stime_<?php echo $id?>" type="hidden" value="<?php echo $str_begintime?>"/>
               		<input id="showtime_<?php echo $id?>" type="hidden" value="开始日期:<em><?php echo $month?></em>月<em><?php echo $day?></em>日<em><?php echo $hour;?></em>时"/>
                    
                    
                    
					<a href="<?php echo $rediturl;?>" class="price"><img src="<?php echo $btnstr;?>" alt="即刻秒杀" /></a>
				</li>
			<?php
				}
				
				}
			
			
			?>
		</ul>
	</div>
	<div class="pagination">
<!--		<a href="#" class="pre">&#171;</a>
		<span class="current">1</span>
		<a href="#">2</a>
		<a href="#">3</a>
		<a href="#">4</a>
		<a href="#" class="next">&#187;</a>-->
        
        <?php echo paging($pages, 'page'); ?>
	</div>
</div>
<?php include('footer.php');?>
<?php include('logintemplate.php');?>
</body>
</html>
